Loops
Loops allow a BindAI workflow to repeat an operation or group of operations while a runtime decision indicates that another iteration should occur. Loops are useful when the same workflow logic must execute repeatedly, such as processing items, repeating validation, or continuing work until a condition is satisfied. BindAI V1 supports loop-based workflow execution as part of its workflow control-flow capabilities. The exact public API for defining workflow loops should be taken from the installed BindAI implementation.What Is a Loop?
A loop creates repeated execution within a workflow. Conceptually:Why Use Loops?
Loops are useful when workflow logic must execute repeatedly. Common examples include:- Processing collections
- Processing batches
- Repeated validation
- Iterative analysis
- Processing paginated data
- Incremental synchronization
- Repeating an operation until a desired state is reached
Loop Execution Flow
A typical loop follows this pattern:Loop State
Loops normally depend on information that changes as execution progresses. For example:Loop Body
The loop body contains the operations performed during one iteration. For example:- Agents
- Tools
- Conditions
- Application processing
- Validation
- Connection-backed tools
Loop Decisions
The continuation decision determines whether another iteration should occur. Conceptually:- More items remain
- A task is incomplete
- A validation condition is not satisfied
- Additional pages are available
- Additional work remains
Example: Processing a Collection
A common loop pattern processes items one at a time.Example: Batch Processing
Loops can process batches incrementally.Example: Pagination
A workflow can repeatedly process pages of data.Example: Repeated Validation
A workflow may repeat processing until a desired state is reached.Loops with Conditions
Conditions can participate inside a loop.Loops with Agents
An Agent node can participate in each loop iteration. For example:- Iterative analysis
- Classification of multiple items
- Repeated planning
- Processing a collection of requests
Loops with Tools
Tool nodes are useful when each iteration performs deterministic work.- Processing records
- Calling an API for each item
- Performing calculations
- Writing application data
- Synchronizing external resources
Loops with Connection-Backed Tools
A loop can repeatedly execute a connection-backed tool. For example:Loops with Knowledge
An Agent node inside a loop can use configured Knowledge during each iteration. For example:Loops with Memory
An Agent node inside a loop can also use configured Memory. For example:Nested Loops
Loops can conceptually be combined with other loops. For example:Avoiding Unbounded Loops
Every loop should have a reliable path toward termination. For example:Loop Progress
A useful loop should make measurable progress. For example:- An item position
- A page number
- A batch identifier
- A completion flag
- Remaining work
- Application state
Loop State and Workflow Variables
Loop state can be stored in workflow variables. For example:Loop Exit
Every loop should have a clear exit path.Loop and Retry Are Different
Loops and retries both involve repeated execution, but they represent different concepts.
Use a loop when repetition is part of the intended workflow behavior.
Retry is a separate capability and is outside the verified advanced V1 workflow scope.
Error Handling Inside Loops
A failure inside a loop body can affect the workflow execution. For example:Testing Loops
Loop behavior should be tested across several scenarios.Zero iterations
The continuation decision is initially false.One iteration
The decision is initially true but becomes false after one iteration.Multiple iterations
The decision remains true for several iterations before becoming false.Non-terminating state
The continuation decision never becomes false. This should be treated as an invalid workflow design or execution condition that requires an appropriate application-level safeguard.Testing Loop State
Tests should verify that workflow state changes as expected. For example:Loop Design Pattern
A reliable loop generally follows this pattern:Common Use Cases
Loop behavior is useful for:- Collection processing
- Batch processing
- Pagination
- Iterative validation
- Incremental synchronization
- Repeated agent processing
- Repeated tool operations
- Processing remaining work
- Iterative application workflows
Best Practices
When designing loops:- Define a clear termination condition.
- Make sure the loop can eventually exit.
- Update the state used by the continuation decision.
- Keep the loop body focused.
- Avoid unnecessary nested loops.
- Make progress explicit.
- Keep loop conditions readable.
- Test zero, one, multiple, and terminating iterations.
- Test the workflow state after each iteration where appropriate.
- Avoid depending on model output alone for termination.
- Keep external operations inside tools or connection-backed tools.
- Define failure behavior for important loop operations.
Current BindAI V1 Scope
BindAI V1 supports loop-based workflow orchestration. Loops can currently be combined with:- Agent nodes
- Tool nodes
- Condition nodes
- Connection-backed tools
- Workflow variables
- Workflow state
- Memory-enabled agents
- Knowledge-enabled agents
- Parallel and Join workflow structures
- Human Tasks
Deferred Features
The following are outside the verified V1 loop feature set:- Advanced retry policies
- Advanced timeout policies
- Workflow scheduling
- Automation triggers
- Distributed loop execution
- Advanced loop monitoring
- Advanced cancellation APIs
- Advanced loop administration
API Accuracy
This documentation intentionally does not assume specific public APIs such as:- The actual import path.
- The actual constructor or factory.
- The actual parameters.
- The loop decision behavior.
- The loop-body behavior.
- The exit behavior.
- Tests demonstrating the behavior.
Summary
Loops allow BindAI workflows to repeat intentional workflow logic. A typical loop follows:Loops repeat intentional workflow behavior; the loop body should make measurable progress toward its exit condition.Specific loop APIs should only be documented after they are verified against the current BindAI implementation and tests.
